package com.zhaoyue.study.netty.socket;

import com.zhaoyue.study.domain.OrderDO;
import com.zhaoyue.study.dto.ResultDTO;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

/**
 * @author zhaoyue
 * @description:
 * @create 2018-11-13 下午4:32
 **/
public class SubReqServerChannelHandler extends ChannelInboundHandlerAdapter {

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        OrderDO orderDO = (OrderDO) msg;
        System.out.println("订单号:" + orderDO.getOrderId());
        ResultDTO resultDTO = new ResultDTO()
                .setCode("0000")
                .setMsg("成功");
        ctx.writeAndFlush(resultDTO);
    }

    @Override
    public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
        ctx.flush();
    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        ctx.close();
    }
}
